import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Projektil here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Projektil extends Actor
{
    boolean x;
    int speed;
    int dmg;
    GreenfootImage img;
    int r;
    GreenfootSound treffer = new GreenfootSound("treffer.wav");
    
    Projektil(boolean xy, int richtung, int s, int d, String p)
    {
        //getWorld().addObject(this, x, y);
        x = xy;
        speed = s;
        dmg = d;
        setImage(p);
        r = richtung;
    }
    
    void treffen()
    {
        Held g = (Held)getOneIntersectingObject(Held.class);
        if(g != null)
        {
            treffer.play();
            g.Lebenverlieren(dmg);
            getWorld().removeObject(this);
        }
    }
    
    /**
     * Act - do whatever the Projektil wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(x) setLocation(getX() + r*speed, getY());
        else setLocation(getX(), getY() + speed);
        treffen();
    }    
}
